package com.jly.edu.controller;

import com.jly.edu.common.lang.Result;
import com.jly.edu.entity.SysUser;
import com.jly.edu.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class TestController {

    @Autowired
    private SysUserService sysUserService;

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/list")
    public Result test(){
        List<SysUser> sysUserList = sysUserService.list();
        return Result.success(sysUserList);
    }
    @PreAuthorize("hasAnyAuthority('sys:user:list')")
    @GetMapping("/list2")
    public Result test2(){
        List<SysUser> sysUserList = sysUserService.list();
        return Result.success(sysUserList);
    }
    public static void main(String[] args) {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String pass = bCryptPasswordEncoder.encode("111111");
        log.info("pass-{}",pass);
        boolean matches = bCryptPasswordEncoder.matches("111111", pass);
        log.info("matches-{}",matches);
    }
}
